package com.lifang.framework.aop.framework.support;

import cn.hutool.core.collection.CollectionUtil;
import com.lifang.framework.aop.TargetSource;
import com.lifang.framework.aop.framework.InterceptorAndDynamicMethodMatcher;

import java.util.List;
import java.util.Vector;

public class AdvisedSupport {

    private boolean proxyTargetClass = true;

    private TargetSource targetSource;

    private final List<InterceptorAndDynamicMethodMatcher> interceptorAndDynamicMethodMatchers = new Vector<>();

    public boolean isProxyTargetClass() {
        return proxyTargetClass;
    }

    public void setProxyTargetClass(boolean proxyTargetClass) {
        this.proxyTargetClass = proxyTargetClass;
    }

    public TargetSource getTargetSource() {
        return targetSource;
    }

    public void setTargetSource(TargetSource targetSource) {
        this.targetSource = targetSource;
    }

    public boolean hasMethodInterceptor() {
        return CollectionUtil.isNotEmpty(this.interceptorAndDynamicMethodMatchers);
    }

    public void addMethodInterceptor(InterceptorAndDynamicMethodMatcher methodMatcher) {
        if(methodMatcher != null){
            interceptorAndDynamicMethodMatchers.remove(methodMatcher);
            interceptorAndDynamicMethodMatchers.add(methodMatcher);
        }
    }

    public List<InterceptorAndDynamicMethodMatcher> getInterceptorAndDynamicMethodMatchers() {
        return interceptorAndDynamicMethodMatchers;
    }
}
